package com.cliang.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cliang.service.dao.impl.DgtOrderDao;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping(value = "/dgtpc/")
public class DgtPcController {
    @Resource
    private DgtOrderDao dgtOrderDao;

    @RequestMapping(value = "getHotOrders")
    @ResponseBody
    public Object getHotOrders() {
        return dgtOrderDao.getHotOrders();
    }

    @RequestMapping(value = "getNewOrders")
    @ResponseBody
    public Object getNewOrders() {
        return dgtOrderDao.getNewOrders();
    }

    @RequestMapping(value = "getTodayPlayOrders")
    @ResponseBody
    public Object getTodayPlayOrders() {
        return dgtOrderDao.getTodayPlayOrders();
    }

    /**
     * 批量删除或批量加载时要获取从前台传来的json格式的数据
     * 类似 [{id:""},{id:""},{id:""},{id:""}]这种
     */
    @RequestMapping(value = "newOrdersBatchAdd")
    @ResponseBody
    public void newOrdersBatchAdd(HttpServletRequest request) {
        String json = request.getParameter("ordersList");
        List<String> list = JSONObject.parseArray(json, String.class);
        dgtOrderDao.updateOrdersIsplay(list);
        for (String orderId : list) {
            dgtOrderDao.insertIsplayOrders(orderId);
        }
    }

    @RequestMapping(value = "newOrdersDel")
    @ResponseBody
    public void newOrdersDel(HttpServletRequest request) {
        String json = request.getParameter("ordersList");
        List<String> list = JSONObject.parseArray(json, String.class);
        dgtOrderDao.deleteOrdersIsplay(list);
    }

    @RequestMapping(value = "hotOrdersAdd")
    @ResponseBody
    public void hotOrdersAdd(HttpServletRequest request) {
        String ordersId = request.getParameter("ordersId");
        dgtOrderDao.insertIsplayOrders(ordersId);
    }
}
